                     MEMBER('dining2.clw')


!--------------------------------------------------
RIDelete:Agents      FUNCTION
Current:Position     STRING(512)
  CODE
  Current:Position = POSITION(AG:KeyId)
  OpenFile:Documents
  LOGOUT(10,Agents,Documents)
  IF ERRORCODE()
    RISaveError
    StandardWarning(Warn:LogoutError,'Delete','Agents')
    DO RICloseFiles
    RETURN(1)
  END
  REGET(AG:KeyId,Current:Position)
  IF RIDelete:Agents:Documents()
    ROLLBACK
    DO RICloseFiles
    RETURN(1)
  END
  DELETE(Agents)
  IF ERRORCODE()
    RISaveError
    StandardWarning(Warn:RIDeleteError,'Agents')
    DO RICloseFiles
    RETURN(1)
  ELSE
    COMMIT
    DO RICloseFiles
    RETURN(0)
  END
!----------------------------------------------------------------------
RICloseFiles ROUTINE
!|
!| This routine is called to close any files opened durint RI processing
!|
  CloseFile:Documents
  EXIT

!--------------------------------------------------
RIDelete:Agents2     FUNCTION
Current:Position     STRING(512)
  CODE
  Current:Position = POSITION(AG2:KeyId)
  OpenFile:Documents
  LOGOUT(10,Agents2,Documents)
  IF ERRORCODE()
    RISaveError
    StandardWarning(Warn:LogoutError,'Delete','Agents2')
    DO RICloseFiles
    RETURN(1)
  END
  REGET(AG2:KeyId,Current:Position)
  IF RIDelete:Agents2:Documents()
    ROLLBACK
    DO RICloseFiles
    RETURN(1)
  END
  DELETE(Agents2)
  IF ERRORCODE()
    RISaveError
    StandardWarning(Warn:RIDeleteError,'Agents2')
    DO RICloseFiles
    RETURN(1)
  ELSE
    COMMIT
    DO RICloseFiles
    RETURN(0)
  END
!----------------------------------------------------------------------
RICloseFiles ROUTINE
!|
!| This routine is called to close any files opened durint RI processing
!|
  CloseFile:Documents
  EXIT

!--------------------------------------------------
RIDelete:D_ACCOUNT   FUNCTION
Current:Position     STRING(512)
  CODE
  Current:Position = POSITION(D_ACC:KEY_ACCOUNT)
  REGET(D_ACC:KEY_ACCOUNT,Current:Position)
  DELETE(D_ACCOUNT)
  IF ERRORCODE()
    RISaveError
    StandardWarning(Warn:RIDeleteError,'D_ACCOUNT')
    RETURN(1)
  ELSE
    RETURN(0)
  END

!--------------------------------------------------
RIDelete:D_BLUDO     FUNCTION
Current:Position     STRING(512)
  CODE
  Current:Position = POSITION(D_BLU:KEY_BLUDO)
  REGET(D_BLU:KEY_BLUDO,Current:Position)
  DELETE(D_BLUDO)
  IF ERRORCODE()
    RISaveError
    StandardWarning(Warn:RIDeleteError,'D_BLUDO')
    RETURN(1)
  ELSE
    RETURN(0)
  END

!--------------------------------------------------
RIDelete:D_CLIENT    FUNCTION
Current:Position     STRING(512)
  CODE
  Current:Position = POSITION(D_CLI1:KEY_CLIENT)
  REGET(D_CLI1:KEY_CLIENT,Current:Position)
  DELETE(D_CLIENT)
  IF ERRORCODE()
    RISaveError
    StandardWarning(Warn:RIDeleteError,'D_CLIENT')
    RETURN(1)
  ELSE
    RETURN(0)
  END

!--------------------------------------------------
RIDelete:D_G_NAME    FUNCTION
Current:Position     STRING(512)
  CODE
  Current:Position = POSITION(D_G_N:KEY_G_NAME)
  REGET(D_G_N:KEY_G_NAME,Current:Position)
  DELETE(D_G_NAME)
  IF ERRORCODE()
    RISaveError
    StandardWarning(Warn:RIDeleteError,'D_G_NAME')
    RETURN(1)
  ELSE
    RETURN(0)
  END

!--------------------------------------------------
RIDelete:D_G_NORM    FUNCTION
Current:Position     STRING(512)
  CODE
  Current:Position = POSITION(D_G_NORM:KEY_G_NORM)
  REGET(D_G_NORM:KEY_G_NORM,Current:Position)
  DELETE(D_G_NORM)
  IF ERRORCODE()
    RISaveError
    StandardWarning(Warn:RIDeleteError,'D_G_NORM')
    RETURN(1)
  ELSE
    RETURN(0)
  END

!--------------------------------------------------
RIDelete:D_ITEMS     FUNCTION
Current:Position     STRING(512)
  CODE
  Current:Position = POSITION(D_ITE:KEY_ITEMS)
  REGET(D_ITE:KEY_ITEMS,Current:Position)
  DELETE(D_ITEMS)
  IF ERRORCODE()
    RISaveError
    StandardWarning(Warn:RIDeleteError,'D_ITEMS')
    RETURN(1)
  ELSE
    RETURN(0)
  END

!--------------------------------------------------
RIDelete:D_LEADS     FUNCTION
Current:Position     STRING(512)
  CODE
  Current:Position = POSITION(D_LEA:KEY_LEADS)
  REGET(D_LEA:KEY_LEADS,Current:Position)
  DELETE(D_LEADS)
  IF ERRORCODE()
    RISaveError
    StandardWarning(Warn:RIDeleteError,'D_LEADS')
    RETURN(1)
  ELSE
    RETURN(0)
  END

!--------------------------------------------------
RIDelete:D_PNITEMS   FUNCTION
Current:Position     STRING(512)
  CODE
  Current:Position = POSITION(D_:PNITEM2)
  REGET(D_:PNITEM2,Current:Position)
  DELETE(D_PNITEMS)
  IF ERRORCODE()
    RISaveError
    StandardWarning(Warn:RIDeleteError,'D_PNITEMS')
    RETURN(1)
  ELSE
    RETURN(0)
  END

!--------------------------------------------------
RIDelete:D_PODR      FUNCTION
Current:Position     STRING(512)
  CODE
  Current:Position = POSITION(D_POD:KEY_PODR)
  REGET(D_POD:KEY_PODR,Current:Position)
  DELETE(D_PODR)
  IF ERRORCODE()
    RISaveError
    StandardWarning(Warn:RIDeleteError,'D_PODR')
    RETURN(1)
  ELSE
    RETURN(0)
  END

!--------------------------------------------------
RIDelete:D_PRICE     FUNCTION
Current:Position     STRING(512)
  CODE
  Current:Position = POSITION(D_PRI:KEY_PRICE)
  REGET(D_PRI:KEY_PRICE,Current:Position)
  DELETE(D_PRICE)
  IF ERRORCODE()
    RISaveError
    StandardWarning(Warn:RIDeleteError,'D_PRICE')
    RETURN(1)
  ELSE
    RETURN(0)
  END

!--------------------------------------------------
RIDelete:D_PRNAKL    FUNCTION
Current:Position     STRING(512)
  CODE
  Current:Position = POSITION(D_PRN:KEY_PRNAKL)
  REGET(D_PRN:KEY_PRNAKL,Current:Position)
  DELETE(D_PRNAKL)
  IF ERRORCODE()
    RISaveError
    StandardWarning(Warn:RIDeleteError,'D_PRNAKL')
    RETURN(1)
  ELSE
    RETURN(0)
  END

!--------------------------------------------------
RIDelete:D_RECEPT_D  FUNCTION
Current:Position     STRING(512)
  CODE
  Current:Position = POSITION(D_REC_D:REC_D)
  REGET(D_REC_D:REC_D,Current:Position)
  DELETE(D_RECEPT_D)
  IF ERRORCODE()
    RISaveError
    StandardWarning(Warn:RIDeleteError,'D_RECEPT_D')
    RETURN(1)
  ELSE
    RETURN(0)
  END

!--------------------------------------------------
RIDelete:D_RECEPT_H  FUNCTION
Current:Position     STRING(512)
  CODE
  Current:Position = POSITION(D_REC_H:REC_H)
  REGET(D_REC_H:REC_H,Current:Position)
  DELETE(D_RECEPT_H)
  IF ERRORCODE()
    RISaveError
    StandardWarning(Warn:RIDeleteError,'D_RECEPT_H')
    RETURN(1)
  ELSE
    RETURN(0)
  END

!--------------------------------------------------
RIDelete:D_REST      FUNCTION
Current:Position     STRING(512)
  CODE
  Current:Position = POSITION(D_RES:KEY_REST)
  REGET(D_RES:KEY_REST,Current:Position)
  DELETE(D_REST)
  IF ERRORCODE()
    RISaveError
    StandardWarning(Warn:RIDeleteError,'D_REST')
    RETURN(1)
  ELSE
    RETURN(0)
  END

!--------------------------------------------------
RIDelete:D_RITEMS    FUNCTION
Current:Position     STRING(512)
  CODE
  Current:Position = POSITION(D_RIT:RITEM2)
  REGET(D_RIT:RITEM2,Current:Position)
  DELETE(D_RITEMS)
  IF ERRORCODE()
    RISaveError
    StandardWarning(Warn:RIDeleteError,'D_RITEMS')
    RETURN(1)
  ELSE
    RETURN(0)
  END

!--------------------------------------------------
RIDelete:D_RNAKL     FUNCTION
Current:Position     STRING(512)
  CODE
  Current:Position = POSITION(D_RNA:KEY_RNAKL)
  REGET(D_RNA:KEY_RNAKL,Current:Position)
  DELETE(D_RNAKL)
  IF ERRORCODE()
    RISaveError
    StandardWarning(Warn:RIDeleteError,'D_RNAKL')
    RETURN(1)
  ELSE
    RETURN(0)
  END

!--------------------------------------------------
RIDelete:D_RPOST_D   FUNCTION
Current:Position     STRING(512)
  CODE
  Current:Position = POSITION(D_RPO_D:KEY_RPOST_D)
  REGET(D_RPO_D:KEY_RPOST_D,Current:Position)
  DELETE(D_RPOST_D)
  IF ERRORCODE()
    RISaveError
    StandardWarning(Warn:RIDeleteError,'D_RPOST_D')
    RETURN(1)
  ELSE
    RETURN(0)
  END

!--------------------------------------------------
RIDelete:D_RPOST_H   FUNCTION
Current:Position     STRING(512)
  CODE
  Current:Position = POSITION(D_RPO_H:KEY_RPOST_H)
  REGET(D_RPO_H:KEY_RPOST_H,Current:Position)
  DELETE(D_RPOST_H)
  IF ERRORCODE()
    RISaveError
    StandardWarning(Warn:RIDeleteError,'D_RPOST_H')
    RETURN(1)
  ELSE
    RETURN(0)
  END

!--------------------------------------------------
RIDelete:D_VBLUDO    FUNCTION
Current:Position     STRING(512)
  CODE
  Current:Position = POSITION(D_VBL:KEY_VBLUDO)
  REGET(D_VBL:KEY_VBLUDO,Current:Position)
  DELETE(D_VBLUDO)
  IF ERRORCODE()
    RISaveError
    StandardWarning(Warn:RIDeleteError,'D_VBLUDO')
    RETURN(1)
  ELSE
    RETURN(0)
  END

!--------------------------------------------------
RIDelete:D_VMENU     FUNCTION
Current:Position     STRING(512)
  CODE
  Current:Position = POSITION(D_VME:KEY_VMENU)
  REGET(D_VME:KEY_VMENU,Current:Position)
  DELETE(D_VMENU)
  IF ERRORCODE()
    RISaveError
    StandardWarning(Warn:RIDeleteError,'D_VMENU')
    RETURN(1)
  ELSE
    RETURN(0)
  END

!--------------------------------------------------
RIDelete:Documents   FUNCTION
Current:Position     STRING(512)
  CODE
  Current:Position = POSITION(DOC:KeyID)
  OpenFile:Journal
  LOGOUT(10,Documents,Journal)
  IF ERRORCODE()
    RISaveError
    StandardWarning(Warn:LogoutError,'Delete','Documents')
    DO RICloseFiles
    RETURN(1)
  END
  REGET(DOC:KeyID,Current:Position)
  IF RIDelete:Documents:Journal()
    ROLLBACK
    DO RICloseFiles
    RETURN(1)
  END
  DELETE(Documents)
  IF ERRORCODE()
    RISaveError
    StandardWarning(Warn:RIDeleteError,'Documents')
    DO RICloseFiles
    RETURN(1)
  ELSE
    COMMIT
    DO RICloseFiles
    RETURN(0)
  END
!----------------------------------------------------------------------
RICloseFiles ROUTINE
!|
!| This routine is called to close any files opened durint RI processing
!|
  CloseFile:Journal
  EXIT

!--------------------------------------------------
RIDelete:Entities    FUNCTION
Current:Position     STRING(512)
  CODE
  Current:Position = POSITION(ENT:KeyID)
  OpenFile:Journal
  LOGOUT(10,Entities,Journal)
  IF ERRORCODE()
    RISaveError
    StandardWarning(Warn:LogoutError,'Delete','Entities')
    DO RICloseFiles
    RETURN(1)
  END
  REGET(ENT:KeyID,Current:Position)
  IF RIDelete:Entities:Journal()
    ROLLBACK
    DO RICloseFiles
    RETURN(1)
  END
  DELETE(Entities)
  IF ERRORCODE()
    RISaveError
    StandardWarning(Warn:RIDeleteError,'Entities')
    DO RICloseFiles
    RETURN(1)
  ELSE
    COMMIT
    DO RICloseFiles
    RETURN(0)
  END
!----------------------------------------------------------------------
RICloseFiles ROUTINE
!|
!| This routine is called to close any files opened durint RI processing
!|
  CloseFile:Journal
  EXIT

!--------------------------------------------------
RIDelete:Journal     FUNCTION
Current:Position     STRING(512)
  CODE
  Current:Position = POSITION(J:KeyID)
  LOGOUT(10,Journal)
  IF ERRORCODE()
    RISaveError
    StandardWarning(Warn:LogoutError,'Delete','Journal')
    RETURN(1)
  END
  REGET(J:KeyID,Current:Position)
  DELETE(Journal)
  IF ERRORCODE()
    RISaveError
    StandardWarning(Warn:RIDeleteError,'Journal')
    RETURN(1)
  ELSE
    COMMIT
    RETURN(0)
  END

!--------------------------------------------------
RIDelete:Series      FUNCTION
Current:Position     STRING(512)
  CODE
  Current:Position = POSITION(SER:KeyID)
  OpenFile:Entities
  OpenFile:Journal
  LOGOUT(10,Series,Entities,Journal)
  IF ERRORCODE()
    RISaveError
    StandardWarning(Warn:LogoutError,'Delete','Series')
    DO RICloseFiles
    RETURN(1)
  END
  REGET(SER:KeyID,Current:Position)
  IF RIDelete:Series:Entities()
    ROLLBACK
    DO RICloseFiles
    RETURN(1)
  END
  IF RIDelete:Series:Journal()
    ROLLBACK
    DO RICloseFiles
    RETURN(1)
  END
  DELETE(Series)
  IF ERRORCODE()
    RISaveError
    StandardWarning(Warn:RIDeleteError,'Series')
    DO RICloseFiles
    RETURN(1)
  ELSE
    COMMIT
    DO RICloseFiles
    RETURN(0)
  END
!----------------------------------------------------------------------
RICloseFiles ROUTINE
!|
!| This routine is called to close any files opened durint RI processing
!|
  CloseFile:Entities
  CloseFile:Journal
  EXIT

!--------------------------------------------------
RIDelete:T_AR_Dtl    FUNCTION
Current:Position     STRING(512)
  CODE
  Current:Position = POSITION(ARD:KeyDoc)
  LOGOUT(10,T_AR_Dtl)
  IF ERRORCODE()
    RISaveError
    StandardWarning(Warn:LogoutError,'Delete','T_AR_Dtl')
    RETURN(1)
  END
  REGET(ARD:KeyDoc,Current:Position)
  DELETE(T_AR_Dtl)
  IF ERRORCODE()
    RISaveError
    StandardWarning(Warn:RIDeleteError,'T_AR_Dtl')
    RETURN(1)
  ELSE
    COMMIT
    RETURN(0)
  END

!--------------------------------------------------
RIDelete:T_AR_Hdr    FUNCTION
Current:Position     STRING(512)
  CODE
  Current:Position = POSITION(ARH:KeyID)
  LOGOUT(10,T_AR_Hdr)
  IF ERRORCODE()
    RISaveError
    StandardWarning(Warn:LogoutError,'Delete','T_AR_Hdr')
    RETURN(1)
  END
  REGET(ARH:KeyID,Current:Position)
  DELETE(T_AR_Hdr)
  IF ERRORCODE()
    RISaveError
    StandardWarning(Warn:RIDeleteError,'T_AR_Hdr')
    RETURN(1)
  ELSE
    COMMIT
    RETURN(0)
  END

!--------------------------------------------------
RIDelete:T_Accounts  FUNCTION
Current:Position     STRING(512)
  CODE
  Current:Position = POSITION(ACC2:KeyName)
  LOGOUT(10,T_Accounts)
  IF ERRORCODE()
    RISaveError
    StandardWarning(Warn:LogoutError,'Delete','T_Accounts')
    RETURN(1)
  END
  REGET(ACC2:KeyName,Current:Position)
  DELETE(T_Accounts)
  IF ERRORCODE()
    RISaveError
    StandardWarning(Warn:RIDeleteError,'T_Accounts')
    RETURN(1)
  ELSE
    COMMIT
    RETURN(0)
  END

!--------------------------------------------------
RIDelete:T_Clients   FUNCTION
Current:Position     STRING(512)
  CODE
  Current:Position = POSITION(CLI:KeyId)
  OpenFile:T_Invoices
  LOGOUT(10,T_Clients,T_Invoices)
  IF ERRORCODE()
    RISaveError
    StandardWarning(Warn:LogoutError,'Delete','T_Clients')
    DO RICloseFiles
    RETURN(1)
  END
  REGET(CLI:KeyId,Current:Position)
  IF RIDelete:T_Clients:T_Invoices()
    ROLLBACK
    DO RICloseFiles
    RETURN(1)
  END
  DELETE(T_Clients)
  IF ERRORCODE()
    RISaveError
    StandardWarning(Warn:RIDeleteError,'T_Clients')
    DO RICloseFiles
    RETURN(1)
  ELSE
    COMMIT
    DO RICloseFiles
    RETURN(0)
  END
!----------------------------------------------------------------------
RICloseFiles ROUTINE
!|
!| This routine is called to close any files opened durint RI processing
!|
  CloseFile:T_Invoices
  EXIT

!--------------------------------------------------
RIDelete:T_Dish_grp  FUNCTION
Current:Position     STRING(512)
  CODE
  Current:Position = POSITION(DGRP:KeyID)
  OpenFile:T_Dishes
  LOGOUT(10,T_Dish_grp)
  IF ERRORCODE()
    RISaveError
    StandardWarning(Warn:LogoutError,'Delete','T_Dish_grp')
    DO RICloseFiles
    RETURN(1)
  END
  REGET(DGRP:KeyID,Current:Position)
  IF RIDelete:T_Dish_grp:T_Dishes()
    ROLLBACK
    DO RICloseFiles
    RETURN(1)
  END
  DELETE(T_Dish_grp)
  IF ERRORCODE()
    RISaveError
    StandardWarning(Warn:RIDeleteError,'T_Dish_grp')
    DO RICloseFiles
    RETURN(1)
  ELSE
    COMMIT
    DO RICloseFiles
    RETURN(0)
  END
!----------------------------------------------------------------------
RICloseFiles ROUTINE
!|
!| This routine is called to close any files opened durint RI processing
!|
  CloseFile:T_Dishes
  EXIT

!--------------------------------------------------
RIDelete:T_Dishes    FUNCTION
Current:Position     STRING(512)
  CODE
  Current:Position = POSITION(DIS:KeyID)
  OpenFile:T_Recipe_Hdr
  LOGOUT(10,T_Dishes,T_Recipe_Hdr)
  IF ERRORCODE()
    RISaveError
    StandardWarning(Warn:LogoutError,'Delete','T_Dishes')
    DO RICloseFiles
    RETURN(1)
  END
  REGET(DIS:KeyID,Current:Position)
  IF RIDelete:T_Dishes:T_Recipe_Hdr()
    ROLLBACK
    DO RICloseFiles
    RETURN(1)
  END
  DELETE(T_Dishes)
  IF ERRORCODE()
    RISaveError
    StandardWarning(Warn:RIDeleteError,'T_Dishes')
    DO RICloseFiles
    RETURN(1)
  ELSE
    COMMIT
    DO RICloseFiles
    RETURN(0)
  END
!----------------------------------------------------------------------
RICloseFiles ROUTINE
!|
!| This routine is called to close any files opened durint RI processing
!|
  CloseFile:T_Recipe_Hdr
  EXIT

!--------------------------------------------------
RIDelete:T_G_Name    FUNCTION
Current:Position     STRING(512)
  CODE
  Current:Position = POSITION(GNAM:KeyID)
  LOGOUT(10,T_G_Name)
  IF ERRORCODE()
    RISaveError
    StandardWarning(Warn:LogoutError,'Delete','T_G_Name')
    RETURN(1)
  END
  REGET(GNAM:KeyID,Current:Position)
  DELETE(T_G_Name)
  IF ERRORCODE()
    RISaveError
    StandardWarning(Warn:RIDeleteError,'T_G_Name')
    RETURN(1)
  ELSE
    COMMIT
    RETURN(0)
  END

!--------------------------------------------------
RIDelete:T_G_Norm    FUNCTION
Current:Position     STRING(512)
  CODE
  Current:Position = POSITION(GNORM:KeyID)
  LOGOUT(10,T_G_Norm)
  IF ERRORCODE()
    RISaveError
    StandardWarning(Warn:LogoutError,'Delete','T_G_Norm')
    RETURN(1)
  END
  REGET(GNORM:KeyID,Current:Position)
  DELETE(T_G_Norm)
  IF ERRORCODE()
    RISaveError
    StandardWarning(Warn:RIDeleteError,'T_G_Norm')
    RETURN(1)
  ELSE
    COMMIT
    RETURN(0)
  END

!--------------------------------------------------
RIDelete:T_Inventory FUNCTION
Current:Position     STRING(512)
  CODE
  Current:Position = POSITION(INV:KeyPerson)
  OpenFile:T_Invoice_Items
  OpenFile:T_Lots
  OpenFile:T_Orgns
  LOGOUT(10,T_Inventory,T_Invoice_Items,T_Lots,T_Orgns)
  IF ERRORCODE()
    RISaveError
    StandardWarning(Warn:LogoutError,'Delete','T_Inventory')
    DO RICloseFiles
    RETURN(1)
  END
  REGET(INV:KeyPerson,Current:Position)
  IF RIDelete:T_Inventory:T_Lots()
    ROLLBACK
    DO RICloseFiles
    RETURN(1)
  END
  IF RIDelete:T_Inventory:T_Orgns()
    ROLLBACK
    DO RICloseFiles
    RETURN(1)
  END
  DELETE(T_Inventory)
  IF ERRORCODE()
    RISaveError
    StandardWarning(Warn:RIDeleteError,'T_Inventory')
    DO RICloseFiles
    RETURN(1)
  ELSE
    COMMIT
    DO RICloseFiles
    RETURN(0)
  END
!----------------------------------------------------------------------
RICloseFiles ROUTINE
!|
!| This routine is called to close any files opened durint RI processing
!|
  CloseFile:T_Invoice_Items
  CloseFile:T_Lots
  CloseFile:T_Orgns
  EXIT

!--------------------------------------------------
RIDelete:T_Invoice_Items FUNCTION
Current:Position     STRING(512)
  CODE
  Current:Position = POSITION(INIT:KeyItem)
  LOGOUT(10,T_Invoice_Items)
  IF ERRORCODE()
    RISaveError
    StandardWarning(Warn:LogoutError,'Delete','T_Invoice_Items')
    RETURN(1)
  END
  REGET(INIT:KeyItem,Current:Position)
  DELETE(T_Invoice_Items)
  IF ERRORCODE()
    RISaveError
    StandardWarning(Warn:RIDeleteError,'T_Invoice_Items')
    RETURN(1)
  ELSE
    COMMIT
    RETURN(0)
  END

!--------------------------------------------------
RIDelete:T_Invoices  FUNCTION
Current:Position     STRING(512)
  CODE
  Current:Position = POSITION(INVC:KeyID)
  OpenFile:T_Invoice_Items
  LOGOUT(10,T_Invoices,T_Invoice_Items)
  IF ERRORCODE()
    RISaveError
    StandardWarning(Warn:LogoutError,'Delete','T_Invoices')
    DO RICloseFiles
    RETURN(1)
  END
  REGET(INVC:KeyID,Current:Position)
  IF RIDelete:T_Invoices:T_Invoice_Items()
    ROLLBACK
    DO RICloseFiles
    RETURN(1)
  END
  DELETE(T_Invoices)
  IF ERRORCODE()
    RISaveError
    StandardWarning(Warn:RIDeleteError,'T_Invoices')
    DO RICloseFiles
    RETURN(1)
  ELSE
    COMMIT
    DO RICloseFiles
    RETURN(0)
  END
!----------------------------------------------------------------------
RICloseFiles ROUTINE
!|
!| This routine is called to close any files opened durint RI processing
!|
  CloseFile:T_Invoice_Items
  EXIT

!--------------------------------------------------
RIDelete:T_Item_grps FUNCTION
Current:Position     STRING(512)
  CODE
  Current:Position = POSITION(ITMG:KeyID)
  OpenFile:T_Items
  LOGOUT(10,T_Item_grps)
  IF ERRORCODE()
    RISaveError
    StandardWarning(Warn:LogoutError,'Delete','T_Item_grps')
    DO RICloseFiles
    RETURN(1)
  END
  REGET(ITMG:KeyID,Current:Position)
  IF RIDelete:T_Item_grps:T_Items()
    ROLLBACK
    DO RICloseFiles
    RETURN(1)
  END
  DELETE(T_Item_grps)
  IF ERRORCODE()
    RISaveError
    StandardWarning(Warn:RIDeleteError,'T_Item_grps')
    DO RICloseFiles
    RETURN(1)
  ELSE
    COMMIT
    DO RICloseFiles
    RETURN(0)
  END
!----------------------------------------------------------------------
RICloseFiles ROUTINE
!|
!| This routine is called to close any files opened durint RI processing
!|
  CloseFile:T_Items
  EXIT

!--------------------------------------------------
RIDelete:T_Items     FUNCTION
Current:Position     STRING(512)
  CODE
  Current:Position = POSITION(ITM:KeyID)
  LOGOUT(10,T_Items)
  IF ERRORCODE()
    RISaveError
    StandardWarning(Warn:LogoutError,'Delete','T_Items')
    RETURN(1)
  END
  REGET(ITM:KeyID,Current:Position)
  DELETE(T_Items)
  IF ERRORCODE()
    RISaveError
    StandardWarning(Warn:RIDeleteError,'T_Items')
    RETURN(1)
  ELSE
    COMMIT
    RETURN(0)
  END

!--------------------------------------------------
RIDelete:T_Leads     FUNCTION
Current:Position     STRING(512)
  CODE
  Current:Position = POSITION(LDS:KeyDebet)
  LOGOUT(10,T_Leads)
  IF ERRORCODE()
    RISaveError
    StandardWarning(Warn:LogoutError,'Delete','T_Leads')
    RETURN(1)
  END
  REGET(LDS:KeyDebet,Current:Position)
  DELETE(T_Leads)
  IF ERRORCODE()
    RISaveError
    StandardWarning(Warn:RIDeleteError,'T_Leads')
    RETURN(1)
  ELSE
    COMMIT
    RETURN(0)
  END

!--------------------------------------------------
RIDelete:T_Lots      FUNCTION
Current:Position     STRING(512)
  CODE
  Current:Position = POSITION(LOT:KeyID)
  OpenFile:T_Invoice_Items
  LOGOUT(10,T_Lots,T_Invoice_Items)
  IF ERRORCODE()
    RISaveError
    StandardWarning(Warn:LogoutError,'Delete','T_Lots')
    DO RICloseFiles
    RETURN(1)
  END
  REGET(LOT:KeyID,Current:Position)
  IF RIDelete:T_Lots:T_Invoice_Items()
    ROLLBACK
    DO RICloseFiles
    RETURN(1)
  END
  DELETE(T_Lots)
  IF ERRORCODE()
    RISaveError
    StandardWarning(Warn:RIDeleteError,'T_Lots')
    DO RICloseFiles
    RETURN(1)
  ELSE
    COMMIT
    DO RICloseFiles
    RETURN(0)
  END
!----------------------------------------------------------------------
RICloseFiles ROUTINE
!|
!| This routine is called to close any files opened durint RI processing
!|
  CloseFile:T_Invoice_Items
  EXIT

!--------------------------------------------------
RIDelete:T_Orgns     FUNCTION
Current:Position     STRING(512)
  CODE
  Current:Position = POSITION(ORGN:KeyID)
  OpenFile:T_Invoices
  LOGOUT(10,T_Orgns,T_Invoices)
  IF ERRORCODE()
    RISaveError
    StandardWarning(Warn:LogoutError,'Delete','T_Orgns')
    DO RICloseFiles
    RETURN(1)
  END
  REGET(ORGN:KeyID,Current:Position)
  IF RIDelete:T_Orgns:T_Invoices()
    ROLLBACK
    DO RICloseFiles
    RETURN(1)
  END
  DELETE(T_Orgns)
  IF ERRORCODE()
    RISaveError
    StandardWarning(Warn:RIDeleteError,'T_Orgns')
    DO RICloseFiles
    RETURN(1)
  ELSE
    COMMIT
    DO RICloseFiles
    RETURN(0)
  END
!----------------------------------------------------------------------
RICloseFiles ROUTINE
!|
!| This routine is called to close any files opened durint RI processing
!|
  CloseFile:T_Invoices
  EXIT

!--------------------------------------------------
RIDelete:T_Recipe_Dtl FUNCTION
Current:Position     STRING(512)
  CODE
  Current:Position = POSITION(RCD:Key_Recipe)
  LOGOUT(10,T_Recipe_Dtl)
  IF ERRORCODE()
    RISaveError
    StandardWarning(Warn:LogoutError,'Delete','T_Recipe_Dtl')
    RETURN(1)
  END
  REGET(RCD:Key_Recipe,Current:Position)
  DELETE(T_Recipe_Dtl)
  IF ERRORCODE()
    RISaveError
    StandardWarning(Warn:RIDeleteError,'T_Recipe_Dtl')
    RETURN(1)
  ELSE
    COMMIT
    RETURN(0)
  END

!--------------------------------------------------
RIDelete:T_Recipe_Hdr FUNCTION
Current:Position     STRING(512)
  CODE
  Current:Position = POSITION(RCH:Key_ID)
  OpenFile:T_Recipe_Dtl
  LOGOUT(10,T_Recipe_Hdr,T_Recipe_Dtl)
  IF ERRORCODE()
    RISaveError
    StandardWarning(Warn:LogoutError,'Delete','T_Recipe_Hdr')
    DO RICloseFiles
    RETURN(1)
  END
  REGET(RCH:Key_ID,Current:Position)
  IF RIDelete:T_Recipe_Hdr:T_Recipe_Dtl()
    ROLLBACK
    DO RICloseFiles
    RETURN(1)
  END
  DELETE(T_Recipe_Hdr)
  IF ERRORCODE()
    RISaveError
    StandardWarning(Warn:RIDeleteError,'T_Recipe_Hdr')
    DO RICloseFiles
    RETURN(1)
  ELSE
    COMMIT
    DO RICloseFiles
    RETURN(0)
  END
!----------------------------------------------------------------------
RICloseFiles ROUTINE
!|
!| This routine is called to close any files opened durint RI processing
!|
  CloseFile:T_Recipe_Dtl
  EXIT

!--------------------------------------------------
RIDelete:T_SalesInvoiceItems FUNCTION
Current:Position     STRING(512)
  CODE
  Current:Position = POSITION(SINI:KeyItem)
  OpenFile:T_Items
  LOGOUT(10,T_SalesInvoiceItems,T_Items)
  IF ERRORCODE()
    RISaveError
    StandardWarning(Warn:LogoutError,'Delete','T_SalesInvoiceItems')
    DO RICloseFiles
    RETURN(1)
  END
  REGET(SINI:KeyItem,Current:Position)
  IF RIDelete:T_SalesInvoiceItems:T_Items()
    ROLLBACK
    DO RICloseFiles
    RETURN(1)
  END
  DELETE(T_SalesInvoiceItems)
  IF ERRORCODE()
    RISaveError
    StandardWarning(Warn:RIDeleteError,'T_SalesInvoiceItems')
    DO RICloseFiles
    RETURN(1)
  ELSE
    COMMIT
    DO RICloseFiles
    RETURN(0)
  END
!----------------------------------------------------------------------
RICloseFiles ROUTINE
!|
!| This routine is called to close any files opened durint RI processing
!|
  CloseFile:T_Items
  EXIT

!--------------------------------------------------
RIDelete:T_SalesInvoices FUNCTION
Current:Position     STRING(512)
  CODE
  Current:Position = POSITION(SINV:KeyID)
  OpenFile:T_Clients
  OpenFile:T_Orgns
  OpenFile:T_SalesInvoiceItems
  LOGOUT(10,T_SalesInvoices,T_Clients,T_Orgns,T_SalesInvoiceItems)
  IF ERRORCODE()
    RISaveError
    StandardWarning(Warn:LogoutError,'Delete','T_SalesInvoices')
    DO RICloseFiles
    RETURN(1)
  END
  REGET(SINV:KeyID,Current:Position)
  IF RIDelete:T_SalesInvoices:T_Clients()
    ROLLBACK
    DO RICloseFiles
    RETURN(1)
  END
  IF RIDelete:T_SalesInvoices:T_Orgns()
    ROLLBACK
    DO RICloseFiles
    RETURN(1)
  END
  IF RIDelete:T_SalesInvoices:T_SalesInvoiceItems()
    ROLLBACK
    DO RICloseFiles
    RETURN(1)
  END
  DELETE(T_SalesInvoices)
  IF ERRORCODE()
    RISaveError
    StandardWarning(Warn:RIDeleteError,'T_SalesInvoices')
    DO RICloseFiles
    RETURN(1)
  ELSE
    COMMIT
    DO RICloseFiles
    RETURN(0)
  END
!----------------------------------------------------------------------
RICloseFiles ROUTINE
!|
!| This routine is called to close any files opened durint RI processing
!|
  CloseFile:T_Clients
  CloseFile:T_Orgns
  CloseFile:T_SalesInvoiceItems
  EXIT

!--------------------------------------------------
RIDelete:T_VBludo    FUNCTION
Current:Position     STRING(512)
  CODE
  Current:Position = POSITION(VBL:KeyID)
  LOGOUT(10,T_VBludo)
  IF ERRORCODE()
    RISaveError
    StandardWarning(Warn:LogoutError,'Delete','T_VBludo')
    RETURN(1)
  END
  REGET(VBL:KeyID,Current:Position)
  DELETE(T_VBludo)
  IF ERRORCODE()
    RISaveError
    StandardWarning(Warn:RIDeleteError,'T_VBludo')
    RETURN(1)
  ELSE
    COMMIT
    RETURN(0)
  END

!--------------------------------------------------
RIDelete:T_VMenu     FUNCTION
Current:Position     STRING(512)
  CODE
  Current:Position = POSITION(VMNU:Key_ID)
  LOGOUT(10,T_VMenu)
  IF ERRORCODE()
    RISaveError
    StandardWarning(Warn:LogoutError,'Delete','T_VMenu')
    RETURN(1)
  END
  REGET(VMNU:Key_ID,Current:Position)
  DELETE(T_VMenu)
  IF ERRORCODE()
    RISaveError
    StandardWarning(Warn:RIDeleteError,'T_VMenu')
    RETURN(1)
  ELSE
    COMMIT
    RETURN(0)
  END

!--------------------------------------------------
RIDelete:Units       FUNCTION
Current:Position     STRING(512)
  CODE
  Current:Position = POSITION(UN:KeyID)
  OpenFile:Entities
  OpenFile:Journal
  LOGOUT(10,Units,Entities,Journal)
  IF ERRORCODE()
    RISaveError
    StandardWarning(Warn:LogoutError,'Delete','Units')
    DO RICloseFiles
    RETURN(1)
  END
  REGET(UN:KeyID,Current:Position)
  IF RIDelete:Units:Entities()
    ROLLBACK
    DO RICloseFiles
    RETURN(1)
  END
  IF RIDelete:Units:Journal()
    ROLLBACK
    DO RICloseFiles
    RETURN(1)
  END
  DELETE(Units)
  IF ERRORCODE()
    RISaveError
    StandardWarning(Warn:RIDeleteError,'Units')
    DO RICloseFiles
    RETURN(1)
  ELSE
    COMMIT
    DO RICloseFiles
    RETURN(0)
  END
!----------------------------------------------------------------------
RICloseFiles ROUTINE
!|
!| This routine is called to close any files opened durint RI processing
!|
  CloseFile:Entities
  CloseFile:Journal
  EXIT

!--------------------------------------------------
RIDelete:Agents:Documents FUNCTION
ReturnCode             LONG(0)
SAV:Documents:Record       LIKE(DOC:Record)
SAV:Documents:Position     STRING(512)
    CODE
    SAV:Documents:Record = DOC:Record
    SAV:Documents:Position = POSITION(DOC:KeyID)
    CLEAR(DOC:Record,0)
    DOC:Agent1_id = AG:AG_ID
    SET(DOC:KeyReciever,DOC:KeyReciever)
    LOOP
      NEXT(Documents)
      IF ERRORCODE()
        IF ERRORCODE() = BadRecErr
          ReturnCode = 0
          DO ProcedureReturn
        ELSE
          ReturnCode = 1
          RISaveError
          StandardWarning(Warn:RecordFetchError,'Documents')
          DO ProcedureReturn
        END
      END
      IF AG:AG_ID <> DOC:Agent1_id
        ReturnCode = 0
        DO ProcedureReturn
      END
      RISaveError
      StandardWarning(Warn:RestrictDelete,'Documents')
      ReturnCode = 1
      DO ProcedureReturn
    END
!----------------------------------------------------------------------
ProcedureReturn ROUTINE
    REGET(DOC:KeyID,SAV:Documents:Position)
    DOC:Record = SAV:Documents:Record
    RETURN(ReturnCode)
    EXIT


!--------------------------------------------------
RIDelete:Agents2:Documents FUNCTION
ReturnCode             LONG(0)
SAV:Documents:Record       LIKE(DOC:Record)
SAV:Documents:Position     STRING(512)
    CODE
    SAV:Documents:Record = DOC:Record
    SAV:Documents:Position = POSITION(DOC:KeyID)
    CLEAR(DOC:Record,0)
    DOC:Agent2_id = AG2:AG_ID
    SET(DOC:KeySupplyer,DOC:KeySupplyer)
    LOOP
      NEXT(Documents)
      IF ERRORCODE()
        IF ERRORCODE() = BadRecErr
          ReturnCode = 0
          DO ProcedureReturn
        ELSE
          ReturnCode = 1
          RISaveError
          StandardWarning(Warn:RecordFetchError,'Documents')
          DO ProcedureReturn
        END
      END
      IF AG2:AG_ID <> DOC:Agent2_id
        ReturnCode = 0
        DO ProcedureReturn
      END
      RISaveError
      StandardWarning(Warn:RestrictDelete,'Documents')
      ReturnCode = 1
      DO ProcedureReturn
    END
!----------------------------------------------------------------------
ProcedureReturn ROUTINE
    REGET(DOC:KeyID,SAV:Documents:Position)
    DOC:Record = SAV:Documents:Record
    RETURN(ReturnCode)
    EXIT


!--------------------------------------------------
RIDelete:Documents:Journal FUNCTION
ReturnCode             LONG(0)
SAV:Journal:Record       LIKE(J:Record)
SAV:Journal:Position     STRING(512)
    CODE
    SAV:Journal:Record = J:Record
    SAV:Journal:Position = POSITION(J:KeyID)
    CLEAR(J:Record,0)
    J:DOC_ID = DOC:DOC_ID
    SET(J:KeyDoc,J:KeyDoc)
    LOOP
      NEXT(Journal)
      IF ERRORCODE()
        IF ERRORCODE() = BadRecErr
          ReturnCode = 0
          DO ProcedureReturn
        ELSE
          ReturnCode = 1
          RISaveError
          StandardWarning(Warn:RecordFetchError,'Journal')
          DO ProcedureReturn
        END
      END
      IF DOC:DOC_ID <> J:DOC_ID
        ReturnCode = 0
        DO ProcedureReturn
      END
      DELETE(Journal)
      IF ERRORCODE()
        RISaveError
        StandardWarning(Warn:RIDeleteError,'Journal')
        ReturnCode = 1
        DO ProcedureReturn
      END
    END
!----------------------------------------------------------------------
ProcedureReturn ROUTINE
    REGET(J:KeyID,SAV:Journal:Position)
    J:Record = SAV:Journal:Record
    RETURN(ReturnCode)
    EXIT


!--------------------------------------------------
RIDelete:Entities:Journal FUNCTION
ReturnCode             LONG(0)
SAV:Journal:Record       LIKE(J:Record)
SAV:Journal:Position     STRING(512)
    CODE
    SAV:Journal:Record = J:Record
    SAV:Journal:Position = POSITION(J:KeyID)
    CLEAR(J:Record,0)
    J:J_ENT = ENT:ENT_ID
    SET(J:KeyEnt,J:KeyEnt)
    LOOP
      NEXT(Journal)
      IF ERRORCODE()
        IF ERRORCODE() = BadRecErr
          ReturnCode = 0
          DO ProcedureReturn
        ELSE
          ReturnCode = 1
          RISaveError
          StandardWarning(Warn:RecordFetchError,'Journal')
          DO ProcedureReturn
        END
      END
      IF ENT:ENT_ID <> J:J_ENT
        ReturnCode = 0
        DO ProcedureReturn
      END
      RISaveError
      StandardWarning(Warn:RestrictDelete,'Journal')
      ReturnCode = 1
      DO ProcedureReturn
    END
!----------------------------------------------------------------------
ProcedureReturn ROUTINE
    REGET(J:KeyID,SAV:Journal:Position)
    J:Record = SAV:Journal:Record
    RETURN(ReturnCode)
    EXIT


!--------------------------------------------------
RIDelete:Series:Entities FUNCTION
ReturnCode             LONG(0)
SAV:Entities:Record       LIKE(ENT:Record)
SAV:Entities:Position     STRING(512)
    CODE
    SAV:Entities:Record = ENT:Record
    SAV:Entities:Position = POSITION(ENT:KeyID)
    CLEAR(ENT:Record,0)
    ENT:ENT_ID = SER:ENT_ID
    SET(ENT:KeyID,ENT:KeyID)
    LOOP
      NEXT(Entities)
      IF ERRORCODE()
        IF ERRORCODE() = BadRecErr
          ReturnCode = 0
          DO ProcedureReturn
        ELSE
          ReturnCode = 1
          RISaveError
          StandardWarning(Warn:RecordFetchError,'Entities')
          DO ProcedureReturn
        END
      END
      IF SER:ENT_ID <> ENT:ENT_ID
        ReturnCode = 0
        DO ProcedureReturn
      END
      RISaveError
      StandardWarning(Warn:RestrictDelete,'Entities')
      ReturnCode = 1
      DO ProcedureReturn
    END
!----------------------------------------------------------------------
ProcedureReturn ROUTINE
    REGET(ENT:KeyID,SAV:Entities:Position)
    ENT:Record = SAV:Entities:Record
    RETURN(ReturnCode)
    EXIT


!--------------------------------------------------
RIDelete:Series:Journal FUNCTION
ReturnCode             LONG(0)
SAV:Journal:Record       LIKE(J:Record)
SAV:Journal:Position     STRING(512)
    CODE
    SAV:Journal:Record = J:Record
    SAV:Journal:Position = POSITION(J:KeyID)
    CLEAR(J:Record,0)
    J:SER_ID = SER:SER_ID
    SET(J:KeySer,J:KeySer)
    LOOP
      NEXT(Journal)
      IF ERRORCODE()
        IF ERRORCODE() = BadRecErr
          ReturnCode = 0
          DO ProcedureReturn
        ELSE
          ReturnCode = 1
          RISaveError
          StandardWarning(Warn:RecordFetchError,'Journal')
          DO ProcedureReturn
        END
      END
      IF SER:SER_ID <> J:SER_ID
        ReturnCode = 0
        DO ProcedureReturn
      END
      RISaveError
      StandardWarning(Warn:RestrictDelete,'Journal')
      ReturnCode = 1
      DO ProcedureReturn
    END
!----------------------------------------------------------------------
ProcedureReturn ROUTINE
    REGET(J:KeyID,SAV:Journal:Position)
    J:Record = SAV:Journal:Record
    RETURN(ReturnCode)
    EXIT


!--------------------------------------------------
RIDelete:T_Clients:T_Invoices FUNCTION
ReturnCode             LONG(0)
SAV:T_Invoices:Record       LIKE(INVC:Record)
SAV:T_Invoices:Position     STRING(512)
    CODE
    SAV:T_Invoices:Record = INVC:Record
    SAV:T_Invoices:Position = POSITION(INVC:KeyID)
    CLEAR(INVC:Record,0)
    INVC:Supplyer_ID = CLI:ID
    SET(INVC:KeySupplyer,INVC:KeySupplyer)
    LOOP
      NEXT(T_Invoices)
      IF ERRORCODE()
        IF ERRORCODE() = BadRecErr
          ReturnCode = 0
          DO ProcedureReturn
        ELSE
          ReturnCode = 1
          RISaveError
          StandardWarning(Warn:RecordFetchError,'T_Invoices')
          DO ProcedureReturn
        END
      END
      IF CLI:ID <> INVC:Supplyer_ID
        ReturnCode = 0
        DO ProcedureReturn
      END
      RISaveError
      StandardWarning(Warn:RestrictDelete,'T_Invoices')
      ReturnCode = 1
      DO ProcedureReturn
    END
!----------------------------------------------------------------------
ProcedureReturn ROUTINE
    REGET(INVC:KeyID,SAV:T_Invoices:Position)
    INVC:Record = SAV:T_Invoices:Record
    RETURN(ReturnCode)
    EXIT


!--------------------------------------------------
RIDelete:T_Dish_grp:T_Dishes FUNCTION
ReturnCode             LONG(0)
SAV:T_Dishes:Record       LIKE(DIS:Record)
SAV:T_Dishes:Position     STRING(512)
    CODE
    SAV:T_Dishes:Record = DIS:Record
    SAV:T_Dishes:Position = POSITION(DIS:KeyID)
    CLEAR(DIS:Record,0)
    DIS:GRP_ID = DGRP:ID
    CLEAR(DIS:NAME,-1)
    SET(DIS:KeyGrp,DIS:KeyGrp)
    LOOP
      NEXT(T_Dishes)
      IF ERRORCODE()
        IF ERRORCODE() = BadRecErr
          ReturnCode = 0
          DO ProcedureReturn
        ELSE
          ReturnCode = 1
          RISaveError
          StandardWarning(Warn:RecordFetchError,'T_Dishes')
          DO ProcedureReturn
        END
      END
      IF DGRP:ID <> DIS:GRP_ID
        ReturnCode = 0
        DO ProcedureReturn
      END
      RISaveError
      StandardWarning(Warn:RestrictDelete,'T_Dishes')
      ReturnCode = 1
      DO ProcedureReturn
    END
!----------------------------------------------------------------------
ProcedureReturn ROUTINE
    REGET(DIS:KeyID,SAV:T_Dishes:Position)
    DIS:Record = SAV:T_Dishes:Record
    RETURN(ReturnCode)
    EXIT


!--------------------------------------------------
RIDelete:T_Dishes:T_Recipe_Hdr FUNCTION
ReturnCode             LONG(0)
SAV:T_Recipe_Hdr:Record       LIKE(RCH:Record)
SAV:T_Recipe_Hdr:Position     STRING(512)
    CODE
    SAV:T_Recipe_Hdr:Record = RCH:Record
    SAV:T_Recipe_Hdr:Position = POSITION(RCH:Key_ID)
    CLEAR(RCH:Record,0)
    RCH:DISH_ID = DIS:ID
    SET(RCH:Key_Dishes,RCH:Key_Dishes)
    LOOP
      NEXT(T_Recipe_Hdr)
      IF ERRORCODE()
        IF ERRORCODE() = BadRecErr
          ReturnCode = 0
          DO ProcedureReturn
        ELSE
          ReturnCode = 1
          RISaveError
          StandardWarning(Warn:RecordFetchError,'T_Recipe_Hdr')
          DO ProcedureReturn
        END
      END
      IF DIS:ID <> RCH:DISH_ID
        ReturnCode = 0
        DO ProcedureReturn
      END
      RISaveError
      StandardWarning(Warn:RestrictDelete,'T_Recipe_Hdr')
      ReturnCode = 1
      DO ProcedureReturn
    END
!----------------------------------------------------------------------
ProcedureReturn ROUTINE
    REGET(RCH:Key_ID,SAV:T_Recipe_Hdr:Position)
    RCH:Record = SAV:T_Recipe_Hdr:Record
    RETURN(ReturnCode)
    EXIT


!--------------------------------------------------
RIDelete:T_Inventory:T_Lots FUNCTION
ReturnCode             LONG(0)
SAV:T_Lots:Record       LIKE(LOT:Record)
SAV:T_Lots:Position     STRING(512)
    CODE
    SAV:T_Lots:Record = LOT:Record
    SAV:T_Lots:Position = POSITION(LOT:KeyID)
    CLEAR(LOT:Record,0)
    LOT:LOT_ID = INV:LOT_ID
    SET(LOT:KeyID,LOT:KeyID)
    LOOP
      NEXT(T_Lots)
      IF ERRORCODE()
        IF ERRORCODE() = BadRecErr
          ReturnCode = 0
          DO ProcedureReturn
        ELSE
          ReturnCode = 1
          RISaveError
          StandardWarning(Warn:RecordFetchError,'T_Lots')
          DO ProcedureReturn
        END
      END
      IF INV:LOT_ID <> LOT:LOT_ID
        ReturnCode = 0
        DO ProcedureReturn
      END
      IF RIDelete:T_Lots:T_Invoice_Items()
        ReturnCode = 1
        DO ProcedureReturn
      END
      DELETE(T_Lots)
      IF ERRORCODE()
        RISaveError
        StandardWarning(Warn:RIDeleteError,'T_Lots')
        ReturnCode = 1
        DO ProcedureReturn
      END
    END
!----------------------------------------------------------------------
ProcedureReturn ROUTINE
    REGET(LOT:KeyID,SAV:T_Lots:Position)
    LOT:Record = SAV:T_Lots:Record
    RETURN(ReturnCode)
    EXIT


!--------------------------------------------------
RIDelete:T_Inventory:T_Orgns FUNCTION
ReturnCode             LONG(0)
SAV:T_Orgns:Record       LIKE(ORGN:Record)
SAV:T_Orgns:Position     STRING(512)
    CODE
    SAV:T_Orgns:Record = ORGN:Record
    SAV:T_Orgns:Position = POSITION(ORGN:KeyID)
    CLEAR(ORGN:Record,0)
    ORGN:ID = INV:PERSON_ID
    SET(ORGN:KeyID,ORGN:KeyID)
    LOOP
      NEXT(T_Orgns)
      IF ERRORCODE()
        IF ERRORCODE() = BadRecErr
          ReturnCode = 0
          DO ProcedureReturn
        ELSE
          ReturnCode = 1
          RISaveError
          StandardWarning(Warn:RecordFetchError,'T_Orgns')
          DO ProcedureReturn
        END
      END
      IF INV:PERSON_ID <> ORGN:ID
        ReturnCode = 0
        DO ProcedureReturn
      END
      RISaveError
      StandardWarning(Warn:RestrictDelete,'T_Orgns')
      ReturnCode = 1
      DO ProcedureReturn
    END
!----------------------------------------------------------------------
ProcedureReturn ROUTINE
    REGET(ORGN:KeyID,SAV:T_Orgns:Position)
    ORGN:Record = SAV:T_Orgns:Record
    RETURN(ReturnCode)
    EXIT


!--------------------------------------------------
RIDelete:T_Invoices:T_Invoice_Items FUNCTION
ReturnCode             LONG(0)
SAV:T_Invoice_Items:Record       LIKE(INIT:Record)
SAV:T_Invoice_Items:Position     STRING(512)
    CODE
    SAV:T_Invoice_Items:Record = INIT:Record
    SAV:T_Invoice_Items:Position = POSITION(INIT:KeyItem)
    CLEAR(INIT:Record,0)
    INIT:ID_DOC = INVC:ID
    SET(INIT:KeyDoc,INIT:KeyDoc)
    LOOP
      NEXT(T_Invoice_Items)
      IF ERRORCODE()
        IF ERRORCODE() = BadRecErr
          ReturnCode = 0
          DO ProcedureReturn
        ELSE
          ReturnCode = 1
          RISaveError
          StandardWarning(Warn:RecordFetchError,'T_Invoice_Items')
          DO ProcedureReturn
        END
      END
      IF INVC:ID <> INIT:ID_DOC
        ReturnCode = 0
        DO ProcedureReturn
      END
      RISaveError
      StandardWarning(Warn:RestrictDelete,'T_Invoice_Items')
      ReturnCode = 1
      DO ProcedureReturn
    END
!----------------------------------------------------------------------
ProcedureReturn ROUTINE
    REGET(INIT:KeyItem,SAV:T_Invoice_Items:Position)
    INIT:Record = SAV:T_Invoice_Items:Record
    RETURN(ReturnCode)
    EXIT


!--------------------------------------------------
RIDelete:T_Item_grps:T_Items FUNCTION
ReturnCode             LONG(0)
SAV:T_Items:Record       LIKE(ITM:Record)
SAV:T_Items:Position     STRING(512)
    CODE
    SAV:T_Items:Record = ITM:Record
    SAV:T_Items:Position = POSITION(ITM:KeyID)
    CLEAR(ITM:Record,0)
    ITM:GRP_ID = ITMG:ID
    CLEAR(ITM:NAME,-1)
    SET(ITM:KeyGrp,ITM:KeyGrp)
    LOOP
      NEXT(T_Items)
      IF ERRORCODE()
        IF ERRORCODE() = BadRecErr
          ReturnCode = 0
          DO ProcedureReturn
        ELSE
          ReturnCode = 1
          RISaveError
          StandardWarning(Warn:RecordFetchError,'T_Items')
          DO ProcedureReturn
        END
      END
      IF ITMG:ID <> ITM:GRP_ID
        ReturnCode = 0
        DO ProcedureReturn
      END
      RISaveError
      StandardWarning(Warn:RestrictDelete,'T_Items')
      ReturnCode = 1
      DO ProcedureReturn
    END
!----------------------------------------------------------------------
ProcedureReturn ROUTINE
    REGET(ITM:KeyID,SAV:T_Items:Position)
    ITM:Record = SAV:T_Items:Record
    RETURN(ReturnCode)
    EXIT


!--------------------------------------------------
RIDelete:T_Lots:T_Invoice_Items FUNCTION
ReturnCode             LONG(0)
SAV:T_Invoice_Items:Record       LIKE(INIT:Record)
SAV:T_Invoice_Items:Position     STRING(512)
    CODE
    SAV:T_Invoice_Items:Record = INIT:Record
    SAV:T_Invoice_Items:Position = POSITION(INIT:KeyItem)
    CLEAR(INIT:Record,0)
    INIT:LOT_ID = LOT:LOT_ID
    SET(INIT:KeyItem,INIT:KeyItem)
    LOOP
      NEXT(T_Invoice_Items)
      IF ERRORCODE()
        IF ERRORCODE() = BadRecErr
          ReturnCode = 0
          DO ProcedureReturn
        ELSE
          ReturnCode = 1
          RISaveError
          StandardWarning(Warn:RecordFetchError,'T_Invoice_Items')
          DO ProcedureReturn
        END
      END
      IF LOT:LOT_ID <> INIT:LOT_ID
        ReturnCode = 0
        DO ProcedureReturn
      END
      RISaveError
      StandardWarning(Warn:RestrictDelete,'T_Invoice_Items')
      ReturnCode = 1
      DO ProcedureReturn
    END
!----------------------------------------------------------------------
ProcedureReturn ROUTINE
    REGET(INIT:KeyItem,SAV:T_Invoice_Items:Position)
    INIT:Record = SAV:T_Invoice_Items:Record
    RETURN(ReturnCode)
    EXIT


!--------------------------------------------------
RIDelete:T_Orgns:T_Invoices FUNCTION
ReturnCode             LONG(0)
SAV:T_Invoices:Record       LIKE(INVC:Record)
SAV:T_Invoices:Position     STRING(512)
    CODE
    SAV:T_Invoices:Record = INVC:Record
    SAV:T_Invoices:Position = POSITION(INVC:KeyID)
    CLEAR(INVC:Record,0)
    INVC:Person_id = ORGN:ID
    SET(INVC:KeyPerson,INVC:KeyPerson)
    LOOP
      NEXT(T_Invoices)
      IF ERRORCODE()
        IF ERRORCODE() = BadRecErr
          ReturnCode = 0
          DO ProcedureReturn
        ELSE
          ReturnCode = 1
          RISaveError
          StandardWarning(Warn:RecordFetchError,'T_Invoices')
          DO ProcedureReturn
        END
      END
      IF ORGN:ID <> INVC:Person_id
        ReturnCode = 0
        DO ProcedureReturn
      END
      RISaveError
      StandardWarning(Warn:RestrictDelete,'T_Invoices')
      ReturnCode = 1
      DO ProcedureReturn
    END
!----------------------------------------------------------------------
ProcedureReturn ROUTINE
    REGET(INVC:KeyID,SAV:T_Invoices:Position)
    INVC:Record = SAV:T_Invoices:Record
    RETURN(ReturnCode)
    EXIT


!--------------------------------------------------
RIDelete:T_Recipe_Hdr:T_Recipe_Dtl FUNCTION
ReturnCode             LONG(0)
SAV:T_Recipe_Dtl:Record       LIKE(RCD:Record)
SAV:T_Recipe_Dtl:Position     STRING(512)
    CODE
    SAV:T_Recipe_Dtl:Record = RCD:Record
    SAV:T_Recipe_Dtl:Position = POSITION(RCD:Key_Recipe)
    CLEAR(RCD:Record,0)
    RCD:Recipe_id = RCH:ID
    SET(RCD:Key_Recipe,RCD:Key_Recipe)
    LOOP
      NEXT(T_Recipe_Dtl)
      IF ERRORCODE()
        IF ERRORCODE() = BadRecErr
          ReturnCode = 0
          DO ProcedureReturn
        ELSE
          ReturnCode = 1
          RISaveError
          StandardWarning(Warn:RecordFetchError,'T_Recipe_Dtl')
          DO ProcedureReturn
        END
      END
      IF RCH:ID <> RCD:Recipe_id
        ReturnCode = 0
        DO ProcedureReturn
      END
    END
!----------------------------------------------------------------------
ProcedureReturn ROUTINE
    REGET(RCD:Key_Recipe,SAV:T_Recipe_Dtl:Position)
    RCD:Record = SAV:T_Recipe_Dtl:Record
    RETURN(ReturnCode)
    EXIT


!--------------------------------------------------
RIDelete:T_SalesInvoiceItems:T_Items FUNCTION
ReturnCode             LONG(0)
SAV:T_Items:Record       LIKE(ITM:Record)
SAV:T_Items:Position     STRING(512)
    CODE
    SAV:T_Items:Record = ITM:Record
    SAV:T_Items:Position = POSITION(ITM:KeyID)
    CLEAR(ITM:Record,0)
    ITM:ID = SINI:Item_id
    SET(ITM:KeyID,ITM:KeyID)
    LOOP
      NEXT(T_Items)
      IF ERRORCODE()
        IF ERRORCODE() = BadRecErr
          ReturnCode = 0
          DO ProcedureReturn
        ELSE
          ReturnCode = 1
          RISaveError
          StandardWarning(Warn:RecordFetchError,'T_Items')
          DO ProcedureReturn
        END
      END
      IF SINI:Item_id <> ITM:ID
        ReturnCode = 0
        DO ProcedureReturn
      END
      RISaveError
      StandardWarning(Warn:RestrictDelete,'T_Items')
      ReturnCode = 1
      DO ProcedureReturn
    END
!----------------------------------------------------------------------
ProcedureReturn ROUTINE
    REGET(ITM:KeyID,SAV:T_Items:Position)
    ITM:Record = SAV:T_Items:Record
    RETURN(ReturnCode)
    EXIT


!--------------------------------------------------
RIDelete:T_SalesInvoices:T_Clients FUNCTION
ReturnCode             LONG(0)
SAV:T_Clients:Record       LIKE(CLI:Record)
SAV:T_Clients:Position     STRING(512)
    CODE
    SAV:T_Clients:Record = CLI:Record
    SAV:T_Clients:Position = POSITION(CLI:KeyId)
    CLEAR(CLI:Record,0)
    CLI:ID = SINV:VENDOR_ID
    SET(CLI:KeyId,CLI:KeyId)
    LOOP
      NEXT(T_Clients)
      IF ERRORCODE()
        IF ERRORCODE() = BadRecErr
          ReturnCode = 0
          DO ProcedureReturn
        ELSE
          ReturnCode = 1
          RISaveError
          StandardWarning(Warn:RecordFetchError,'T_Clients')
          DO ProcedureReturn
        END
      END
      IF SINV:VENDOR_ID <> CLI:ID
        ReturnCode = 0
        DO ProcedureReturn
      END
      RISaveError
      StandardWarning(Warn:RestrictDelete,'T_Clients')
      ReturnCode = 1
      DO ProcedureReturn
    END
!----------------------------------------------------------------------
ProcedureReturn ROUTINE
    REGET(CLI:KeyId,SAV:T_Clients:Position)
    CLI:Record = SAV:T_Clients:Record
    RETURN(ReturnCode)
    EXIT


!--------------------------------------------------
RIDelete:T_SalesInvoices:T_Orgns FUNCTION
ReturnCode             LONG(0)
SAV:T_Orgns:Record       LIKE(ORGN:Record)
SAV:T_Orgns:Position     STRING(512)
    CODE
    SAV:T_Orgns:Record = ORGN:Record
    SAV:T_Orgns:Position = POSITION(ORGN:KeyID)
    CLEAR(ORGN:Record,0)
    ORGN:ID = SINV:Persone_id
    SET(ORGN:KeyID,ORGN:KeyID)
    LOOP
      NEXT(T_Orgns)
      IF ERRORCODE()
        IF ERRORCODE() = BadRecErr
          ReturnCode = 0
          DO ProcedureReturn
        ELSE
          ReturnCode = 1
          RISaveError
          StandardWarning(Warn:RecordFetchError,'T_Orgns')
          DO ProcedureReturn
        END
      END
      IF SINV:Persone_id <> ORGN:ID
        ReturnCode = 0
        DO ProcedureReturn
      END
      RISaveError
      StandardWarning(Warn:RestrictDelete,'T_Orgns')
      ReturnCode = 1
      DO ProcedureReturn
    END
!----------------------------------------------------------------------
ProcedureReturn ROUTINE
    REGET(ORGN:KeyID,SAV:T_Orgns:Position)
    ORGN:Record = SAV:T_Orgns:Record
    RETURN(ReturnCode)
    EXIT


!--------------------------------------------------
RIDelete:T_SalesInvoices:T_SalesInvoiceItems FUNCTION
ReturnCode             LONG(0)
SAV:T_SalesInvoiceItems:Record       LIKE(SINI:Record)
SAV:T_SalesInvoiceItems:Position     STRING(512)
    CODE
    SAV:T_SalesInvoiceItems:Record = SINI:Record
    SAV:T_SalesInvoiceItems:Position = POSITION(SINI:KeyItem)
    CLEAR(SINI:Record,0)
    SINI:Invoice_id = SINV:ID
    SET(SINI:KeyInvoiceID,SINI:KeyInvoiceID)
    LOOP
      NEXT(T_SalesInvoiceItems)
      IF ERRORCODE()
        IF ERRORCODE() = BadRecErr
          ReturnCode = 0
          DO ProcedureReturn
        ELSE
          ReturnCode = 1
          RISaveError
          StandardWarning(Warn:RecordFetchError,'T_SalesInvoiceItems')
          DO ProcedureReturn
        END
      END
      IF SINV:ID <> SINI:Invoice_id
        ReturnCode = 0
        DO ProcedureReturn
      END
      RISaveError
      StandardWarning(Warn:RestrictDelete,'T_SalesInvoiceItems')
      ReturnCode = 1
      DO ProcedureReturn
    END
!----------------------------------------------------------------------
ProcedureReturn ROUTINE
    REGET(SINI:KeyItem,SAV:T_SalesInvoiceItems:Position)
    SINI:Record = SAV:T_SalesInvoiceItems:Record
    RETURN(ReturnCode)
    EXIT


!--------------------------------------------------
RIDelete:Units:Entities FUNCTION
ReturnCode             LONG(0)
SAV:Entities:Record       LIKE(ENT:Record)
SAV:Entities:Position     STRING(512)
    CODE
    SAV:Entities:Record = ENT:Record
    SAV:Entities:Position = POSITION(ENT:KeyID)
    CLEAR(ENT:Record,0)
    ENT:UN_ID = UN:UN_ID
    SET(ENT:KeyUN,ENT:KeyUN)
    LOOP
      NEXT(Entities)
      IF ERRORCODE()
        IF ERRORCODE() = BadRecErr
          ReturnCode = 0
          DO ProcedureReturn
        ELSE
          ReturnCode = 1
          RISaveError
          StandardWarning(Warn:RecordFetchError,'Entities')
          DO ProcedureReturn
        END
      END
      IF UN:UN_ID <> ENT:UN_ID
        ReturnCode = 0
        DO ProcedureReturn
      END
      RISaveError
      StandardWarning(Warn:RestrictDelete,'Entities')
      ReturnCode = 1
      DO ProcedureReturn
    END
!----------------------------------------------------------------------
ProcedureReturn ROUTINE
    REGET(ENT:KeyID,SAV:Entities:Position)
    ENT:Record = SAV:Entities:Record
    RETURN(ReturnCode)
    EXIT


!--------------------------------------------------
RIDelete:Units:Journal FUNCTION
ReturnCode             LONG(0)
SAV:Journal:Record       LIKE(J:Record)
SAV:Journal:Position     STRING(512)
    CODE
    SAV:Journal:Record = J:Record
    SAV:Journal:Position = POSITION(J:KeyID)
    CLEAR(J:Record,0)
    J:J_UN = UN:UN_ID
    SET(J:KeyUOM,J:KeyUOM)
    LOOP
      NEXT(Journal)
      IF ERRORCODE()
        IF ERRORCODE() = BadRecErr
          ReturnCode = 0
          DO ProcedureReturn
        ELSE
          ReturnCode = 1
          RISaveError
          StandardWarning(Warn:RecordFetchError,'Journal')
          DO ProcedureReturn
        END
      END
      IF UN:UN_ID <> J:J_UN
        ReturnCode = 0
        DO ProcedureReturn
      END
      RISaveError
      StandardWarning(Warn:RestrictDelete,'Journal')
      ReturnCode = 1
      DO ProcedureReturn
    END
!----------------------------------------------------------------------
ProcedureReturn ROUTINE
    REGET(J:KeyID,SAV:Journal:Position)
    J:Record = SAV:Journal:Record
    RETURN(ReturnCode)
    EXIT

